package com.distribute.framework.model;

import com.distribute.framework.core.web.helper.Utils;
import java.lang.reflect.Field;
import java.util.Date; 
import java.util.Map;
import java.util.HashMap;
import java.util.List;
import java.util.ArrayList;

import javax.annotation.Resource;

import com.distribute.framework.core.web.util.Page;
import com.distribute.framework.core.lang.*; 
import com.distribute.framework.core.web.helper.WebHelper.LzMap;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.util.IbatisMap;
import com.distribute.framework.config.*;
import com.distribute.framework.plugin.*;

@namespace("permissions/role")
public @caption("系统角色") @database(DatabaseNames.distribute_sys) @source("distribute_sys") @table("srv_role") class SrvRole implements java.io.Serializable
{
	private static final long serialVersionUID = 1l;
	private @caption("编号") @column("sr_id")    @primary  @notnull  @note("  ") Long srId;// 主键 非空     
	private @caption("角色名称") @column("sr_name")     @notnull  @note("  ") String srName;// 非空     
	private @caption("角色标识") @column("sr_flag")      @note("  ") String srFlag;//     
	private @caption("角色描述") @column("sr_profile") @like     @note("  ") String srProfile;//     
	private @caption("修改时间") @column("sr_update_time")     @notnull  @note("  ") Date srUpdateTime;// 非空     
	private @caption("添加时间") @column("sr_add_time")     @notnull  @note("  ") Date srAddTime;// 非空     
	private @caption("状态") @column("sr_status")     @notnull  @note(" 1:正常 0:无效  ") Short srStatus;// 非空 1:正常 0:无效     
	 
	//默认构造函数
	public SrvRole(){ 
	
	}
	
	//主键构造函数
	public SrvRole(Long id){
		this.srId = id;
	}
	
	/**所有字段构造函数 
	 SrvRole(
	 	Utils.getString("srName")//角色名称 [非空]
	 	,Utils.getString("srFlag")//角色标识
	 	,Utils.getString("srProfile")//角色描述
	 	,Utils.getDate("srUpdateTime")//修改时间 [非空]
	 	,Utils.getDate("srAddTime")//添加时间 [非空]
	 	,Utils.getShort("srStatus")//状态 [非空]
	 )
	**/
	public SrvRole(String srName,String srFlag,String srProfile,Date srUpdateTime,Date srAddTime,Short srStatus){
		this.srName=srName;
		this.srFlag=srFlag;
		this.srProfile=srProfile;
		this.srUpdateTime=srUpdateTime;
		this.srAddTime=srAddTime;
		this.srStatus=srStatus;
	}
	
	//设置非空字段
	public SrvRole setNotNull(String srName,Date srUpdateTime,Date srAddTime,Short srStatus){
		this.srName=srName;
		this.srUpdateTime=srUpdateTime;
		this.srAddTime=srAddTime;
		this.srStatus=srStatus;
		return this;
	}
	/** 编号 [非空]       **/
	public SrvRole srId(Long srId){
		this.srId = srId;
		this.setSeted(F.srId);
		return this;
	}
	/** 角色名称 [非空]       **/
	public SrvRole srName(String srName){
		this.srName = srName;
		this.setSeted(F.srName);
		return this;
	}
	/** 角色标识        **/
	public SrvRole srFlag(String srFlag){
		this.srFlag = srFlag;
		this.setSeted(F.srFlag);
		return this;
	}
	/** 角色描述        **/
	public SrvRole srProfile(String srProfile){
		this.srProfile = srProfile;
		this.setSeted(F.srProfile);
		return this;
	}
	/** 修改时间 [非空]       **/
	public SrvRole srUpdateTime(Date srUpdateTime){
		this.srUpdateTime = srUpdateTime;
		this.setSeted(F.srUpdateTime);
		return this;
	}
	/** 添加时间 [非空]       **/
	public SrvRole srAddTime(Date srAddTime){
		this.srAddTime = srAddTime;
		this.setSeted(F.srAddTime);
		return this;
	}
	/** 状态 [非空]   1:正常 0:无效     **/
	public SrvRole srStatus(Short srStatus){
		this.srStatus = srStatus;
		this.setSeted(F.srStatus);
		return this;
	}
	
	
	/**
	* 克隆对象
	**/
	public SrvRole clone(){
		SrvRole clone = new SrvRole();
		clone.srName=this.srName;
		clone.srFlag=this.srFlag;
		clone.srProfile=this.srProfile;
		clone.srUpdateTime=this.srUpdateTime;
		clone.srAddTime=this.srAddTime;
		clone.srStatus=this.srStatus;
		return clone;
	}
	/**
	* 清除缓存
	**/
	public void clear(){
		Cache.clearObject(SrvRole.M.class);
		Cache.clearValue(SrvRole.M.class);
		Cache.deleteObject(SrvRole.class, this.getId());
	}
	
	/**
	* 清除缓存
	**/
	public static void clear(Long id){
		Cache.clearObject(SrvRole.M.class);
		Cache.clearValue(SrvRole.M.class);
		Cache.deleteObject(SrvRole.class, id);
	}
	
	
	/**
	 * 根据ID取系统角色
	 * @param id
	 * @return
	 */
	public static @api SrvRole get(Long id){		
		return getSrvRoleById(id);
	}
	/**
	 * 设置ID
	 * @param id
	 * @return
	 */
	public void setId(Long id){		
		this.srId = id;
	}
	
	/**
	 * 获取所有系统角色
	 * @return
	 */
	public static @api List<SrvRole> list(Map params,Integer size){
		return getSrvRoleList(params,size);
	}
	/**
	 * 获取系统角色分页
	 * @return
	 */
	public static @api Page<SrvRole> page(Integer page,Integer size,Map params){
		return getSrvRolePage(page, size , params);
	}
	
	
	/**
	 * 根据查询条件取系统角色
	 * @param params
	 * @return
	 */
	public static @api SrvRole Get(Map params){
		return getSrvRole(params);
	}
	/**
	 * 获取系统角色数
	 * @return
	 */
	public static @api Long count(Map params){
		return getSrvRoleCount(params);
	}
	/**
	 * 获取系统角色数
	 * @return
	 */
	public static @api <T> T eval(String eval,Map params){
		return getSrvRoleEval(eval,params);
	}
	/**
	 * 获取系统角色图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey){
		return getSrvRoleStats(params,sumKey,groupKey,-1);
	}
	/**
	 * 获取系统角色图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> stats(Map params,C sumKey,C groupKey,int dateType){
		return getSrvRoleStats(params,sumKey,groupKey,dateType);
	}
	
	/**
	 * 根据ID取系统角色
	 * @param id
	 * @return
	 */
	public static @api SrvRole getSrvRoleById(Long id){		
		return getSrvRoleDao().getSrvRoleById(id);
	}
	/**
	 * 获取id
	 * @return
	 */
	public Long getId(){
		return this.srId;
	}
	
	
	/**
	 * 根据ID取系统角色的标识键值
	 * @param id
	 * @return
	 */
	public static @api String getKeyValue(Object key){
		Long id = Utils.parseLong(key);	
		if(id==null || id.longValue()==0 ){
			return null;
		}
		String value = null;
		value = Cache.getValue(SrvRole.class, id);
		if(value==null){
			SrvRole srvRole = get(id);
			if(srvRole!=null){
				String strValue = srvRole.getSrName$();
				if(!"SrName".equals("SrName"))
					strValue+="("+srvRole.getSrName$()+")";
				Cache.setValue(SrvRole.class, id ,strValue);
				value = strValue;
			}else{
				Cache.setValue(SrvRole.class, id ,"{"+id+"}",30);
				value = "{"+id+"}";
			}
		}
		/************LAZY3Q_ID_KEYVALUE************/
		/************LAZY3Q_ID_KEYVALUE************/
		return value;
	}	
	
	
	/**
	 * 获取当前对象的键值
	 * @return
	 */
	public String getKeyValue(){
		/************LAZY3Q_CODE_KEYVALUE************/
		/************LAZY3Q_CODE_KEYVALUE************/
		String keyValue = this.getSrName$();
		if(!"SrName".equals("SrName"))
			keyValue+="("+this.getSrName$()+")";
		return keyValue;
	}
	
	
	/**
	 * 根据关键字精确查询系统角色对象
	 * @return
	 */
	public static @api SrvRole find(String key){
		if(Utils.empty(key))return null;
		Map params = new HashMap();
		if(key.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
			params.put("srId", key.toLowerCase().replaceFirst("id:", ""));					
		else{//按标识查询，精确查询
			String strDefinex = "";
			strDefinex+=" or sr_name = '"+key.replaceAll("'", "''")+"'";
			strDefinex="(2=1 "+strDefinex+")";
			params.put("definex",strDefinex);
		}
		/************LAZY3Q_CODE_FIND************/
		/************LAZY3Q_CODE_FIND************/
		return SrvRole.getSrvRole(params);
	}
	
	
	/**
	 * 根据关键字查询系统角色
	 * @return
	 */
	public static @api List<Map> query(String key,int size,Map params,Boolean bObject){
		if(Utils.empty((String)params.get("asc")) && Utils.empty((String)params.get("desc")))//如果未传入排序字段
			params.put("desc","sr_id");//那么，默认以主键降序，传给Dao层
		String strTerm=key;		
		if(!Utils.empty(strTerm)){
			if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
				params.put("srId", strTerm.toLowerCase().replaceFirst("id:", ""));					
			else//按标识查询，模糊查询请带%
			{
				String strDefinex = "";
				strDefinex+=" or sr_name like '%"+strTerm.replaceAll("'", "''")+"%'";
				strDefinex="(2=1 "+strDefinex+")";
				params.put("definex",strDefinex);
			}
		}
		/************LAZY3Q_CODE_QUERY************/
		/************LAZY3Q_CODE_QUERY************/
			
		List<SrvRole> list = page(0,size,params).getResult();
		
		/**
		* OK!取到数据拼成放入Map中，[{value,text,object:{...}},...]
		* value:数据ID，text:数据标识,object,整个对象
		**/
		List<Map> result = new java.util.ArrayList();
		for(SrvRole srvRole:list){
			Map map = new HashMap();
			map.put("key",srvRole.getSrId().toString());
			map.put("value", Utils.js(srvRole.getKeyValue()));
			if(bObject==true)
				map.put("object",srvRole);
			result.add(map);
		}
		/************LAZY3Q_AFTER_QUERY************/
		/************LAZY3Q_AFTER_QUERY************/
		
		return result;
	}
	
	
	
	/**
	 * 获取所有系统角色
	 * @return
	 */
	public static @api List<SrvRole> getSrvRoleList(Map params,Integer size){
		return getSrvRoleDao().getSrvRoleList(params,0,size);
	}
	
	/**
	 * 获取系统角色分页
	 * @return
	 */
	public static @api Page<SrvRole> getSrvRolePage(Integer page,Integer size,Map params){
		if(page==null)page=0;
		if(size==null)size=20;
		return getSrvRoleDao().getSrvRolePage(page, size , params);
	}
	
	/**
	 * 根据查询条件取系统角色
	 * @param params
	 * @return
	 */
	public static @api SrvRole getSrvRole(Map params){
		return getSrvRoleDao().getSrvRole(params);
	}
	
	/**
	 * 保存一个系统角色
	 * @param srvRole
	 * @return
	 */
	public static @api SrvRole saveSrvRole(SrvRole srvRole){
		return getSrvRoleDao().saveSrvRole(srvRole);
	}
	
	/**
	 * 根据条件更新系统角色
	 * @param values
	 * @param params
	 */
	public static @api int updateSrvRoleByConfirm(Map values, Map params){
		return getSrvRoleDao().updateSrvRoleByConfirm(values,params);
	}
	
	/**
	 * 修改一个系统角色
	 * @param srvRole
	 * @return
	 */
	public static @api int updateSrvRole(SrvRole srvRole){
		return getSrvRoleDao().updateSrvRole(srvRole);
	}
	
	/**
	 * 更新系统角色非空字段
	 * @param srvRole
	 */
	public static @api int updateSrvRole$NotNull(SrvRole srvRole){
		return getSrvRoleDao().updateSrvRole$NotNull(srvRole);
	}
	
	/**
	 * 获取系统角色数
	 * @return
	 */
	public static @api Long getSrvRoleCount(Map params){
		return getSrvRoleDao().getSrvRoleCount(params);
	}
		
		
	/**
	 * 获取系统角色自定义求和表达式,比如求和:eval="sum(id)"
	 * @return
	 */	
	public static @api <T> T getSrvRoleEval(String eval,Map params){
		return getSrvRoleDao().getSrvRoleEval(eval,params);
	}
	/**
	 * 获取系统角色图表统计数据
	 * @param params 查询条件
	 * @param sumKey 统计的字段
	 * @param groupKey 分组的字段
	 * @param dateType 1:按年， 2：按月， 3：按周， 4：按日， 5：按小时， 6：月分， 7：日分， 8：点分
	 * @return
	 */
	public static @api List<Map> getSrvRoleStats(Map params,C sumKey,C groupKey,int dateType){
		//TODO:图表统计功能未实现
		
		Map<String,Object> groups=new HashMap();//要分组的字段
		Map<String,Object> sums=new HashMap();//要统计的字段
		
		String[][] dateFormats=new String[][]{
				null,
				new String[]{"%Y","yyyy年","Y"},
				new String[]{"%Y-%m","yyyy年MM月","M"},
				new String[]{"%Y%U","yyyy年第ww周","W"},
				new String[]{"%Y-%m-%d","yyyy年MM月dd日","D"},
				new String[]{"%Y-%m-%d %H","yyyy年MM月dd日 HH点","H"},
				new String[]{"%m","MM月"},
				new String[]{"%d","dd号"},
				new String[]{"%H","HH点"} 
		};
		
		//获取要分组的字段，放入Map中
		if(dateType>0){
			groups.put(groupKey.toString(),"DATE_FORMAT({key},'"+dateFormats[dateType][0]+"')");
		}else{
			groups.put(groupKey.toString(),"{key}");
		}
		if(dateType<6 && dateType>0){ 
			params.put("asc", groupKey.toString()); 
			if(params.get(groupKey.name()+"Start")==null){
				params.put(groupKey.name()+"Start", Utils.date(new Date(), -24, dateFormats[dateType][2]));
			}
		}
		
		
		//获取要统计的字段，放入Map中
		if(sumKey.toString().equals("count")){
			sums.put(sumKey.toString(),"count(*)");
		}else{
			sums.put(sumKey.toString(),"sum({key})");
		}
		
		List<Map> list = getSrvRoleDao().getSrvRoleStats(params,groups,sums);
		
		List<Map> result = new ArrayList();
		for(Map m:list){
			Map map = new HashMap();
			Object value = m.get(sumKey.toString());
			Object name = null;
			Object groupValue = m.get(groupKey.toString());
			if(dateType>0){
				name = Utils.date(Utils.parseDate(groupValue), dateFormats[dateType][1]);
			}else{
				try{
					java.lang.reflect.Method method = SrvRole.class.getMethod("get"+Utils.ForMat(groupKey.toString())+"$");
					method.setAccessible(true);
					name = method.invoke(SrvRole.fromMap(m));
				}catch(Exception ex){
					ex.printStackTrace();
				}
			}
			map.put("name", name);
			map.put("value", value);
			result.add(map);
		}
		return result;
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static int updateSrvRole(Map set,Map where){
		if(set.isEmpty())throw new RuntimeException("set为空");
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		return getSrvRoleDao().updateSrvRoleByConfirm(set, where);
	}
	
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void deleteSrvRole(Map where){
		if(where.isEmpty())throw new RuntimeException("where为空");
		where.put("confirm", "1");
		getSrvRoleDao().deleteSrvRoleByConfirm(where);
	}
	
	/**
	 * 根据条件更新数据
	 * @param set
	 * @param where
	 */
	public static void delete(Long id){
		if(id==null)throw new RuntimeException("id为空");
		getSrvRoleDao().removeSrvRoleById(id);
	}
	
	
	/**
	 * 保存系统角色对象
	 * @param params
	 * @return
	 */
	public SrvRole save(){
		if(this.getSrId()!=null)
			getSrvRoleDao().updateSrvRole(this);
		else
			return getSrvRoleDao().saveSrvRole(this);
		return this;
	}
	
	
	/**
	 * 更新系统角色对象的非空字段,注意跟Service里面的update不一样哦
	 * @param params
	 * @return
	 */
	public int update(){
		return getSrvRoleDao().updateSrvRole$NotNull(this);
	}
	
	
	/**
	 * 删除
	 * @param params
	 * @return
	 */
	public void delete(){
		if(Utils.equals(Utils.config("logic_delete"),"true"))
			getSrvRoleDao().removeSrvRoleById(this.getSrId());
		else
			getSrvRoleDao().deleteSrvRoleById(this.getSrId());
	}
	
	/**
	 * 执行事务
	 * @param function
	 */
	public static <T> T execute(Function function){
		return getSrvRoleDao().executeTransaction(function);
	}
	/*******************************编号**********************************/	
	/**
	* 编号 [非空]      
	**/
	public Long getSrId(){
		if(this.srId!=null){
			return this.srId;
		}
		return this.srId;
	}
	/**
	* 获取编号格式化(toString)
	**/
	public String getSrId$(){
		String strValue="";
		 strValue=Utils.string(this.getSrId());
	 	 return strValue;
	}
	/**
	* 根据编号反格式化
	**/
	public void setSrId$(String strValue){
		if(Utils.empty(strValue)){
			this.srId=null;
			return;
		}
	 	this.srId=Utils.parseLong(strValue);
	}
	
	/**
	* 编号 [非空]      
	**/
	public void setSrId(Long srId){
		this.srId = srId;
		this.setSeted(F.srId);
	}
	
	
	
	
	/*******************************角色名称**********************************/	
	/**
	* 角色名称 [非空]      
	**/
	public String getSrName(){
		if(this.srName!=null){
			return this.srName;
		}
		return this.srName;
	}
	/**
	* 获取角色名称格式化(toString)
	**/
	public String getSrName$(){
		String strValue="";
		 strValue=Utils.string(this.getSrName());
	 	 return strValue;
	}
	/**
	* 根据角色名称反格式化
	**/
	public void setSrName$(String strValue){
		if(Utils.empty(strValue)){
			this.srName=null;
			return;
		}
	 	this.srName=strValue;
	}
	
	/**
	* 角色名称 [非空]      
	**/
	public void setSrName(String srName){
		this.srName = srName;
		this.setSeted(F.srName);
	}
	
	
	
	
	/*******************************角色标识**********************************/	
	/**
	* 角色标识       
	**/
	public String getSrFlag(){
		if(this.srFlag!=null){
			return this.srFlag;
		}
		return this.srFlag;
	}
	/**
	* 获取角色标识格式化(toString)
	**/
	public String getSrFlag$(){
		String strValue="";
		 strValue=Utils.string(this.getSrFlag());
	 	 return strValue;
	}
	/**
	* 根据角色标识反格式化
	**/
	public void setSrFlag$(String strValue){
		if(Utils.empty(strValue)){
			this.srFlag=null;
			return;
		}
	 	this.srFlag=strValue;
	}
	
	/**
	* 角色标识       
	**/
	public void setSrFlag(String srFlag){
		this.srFlag = srFlag;
		this.setSeted(F.srFlag);
	}
	
	
	
	
	/*******************************角色描述**********************************/	
	/**
	* 角色描述       
	**/
	public String getSrProfile(){
		if(this.srProfile!=null){
			return this.srProfile;
		}
		return this.srProfile;
	}
	/**
	* 获取角色描述格式化(toString)
	**/
	public String getSrProfile$(){
		String strValue="";
		 strValue=Utils.string(this.getSrProfile());
	 	 return strValue;
	}
	/**
	* 根据角色描述反格式化
	**/
	public void setSrProfile$(String strValue){
		if(Utils.empty(strValue)){
			this.srProfile=null;
			return;
		}
		this.srProfile=strValue;
	}
	
	/**
	* 角色描述       
	**/
	public void setSrProfile(String srProfile){
		this.srProfile = srProfile;
		this.setSeted(F.srProfile);
	}
	
	
	
	
	/*******************************修改时间**********************************/	
	/**
	* 修改时间 [非空]      
	**/
	public Date getSrUpdateTime(){
		if(this.srUpdateTime!=null){
			return this.srUpdateTime;
		}
		return this.srUpdateTime;
	}
	/**
	* 获取修改时间格式化(toString)
	**/
	public String getSrUpdateTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSrUpdateTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据修改时间反格式化
	**/
	public void setSrUpdateTime$(String strValue){
		if(Utils.empty(strValue)){
			this.srUpdateTime=null;
			return;
		}
	 	this.srUpdateTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 修改时间 [非空]      
	**/
	public void setSrUpdateTime(Date srUpdateTime){
		this.srUpdateTime = srUpdateTime;
		this.setSeted(F.srUpdateTime);
	}
	
	
	
	
	/*******************************添加时间**********************************/	
	/**
	* 添加时间 [非空]      
	**/
	public Date getSrAddTime(){
		if(this.srAddTime!=null){
			return this.srAddTime;
		}
		return this.srAddTime;
	}
	/**
	* 获取添加时间格式化(toString)
	**/
	public String getSrAddTime$(){
		String strValue="";
		 strValue=Utils.string(Utils.date(this.getSrAddTime(),"yyyy-MM-dd HH:mm:ss"));
	 	 return strValue;
	}
	/**
	* 根据添加时间反格式化
	**/
	public void setSrAddTime$(String strValue){
		if(Utils.empty(strValue)){
			this.srAddTime=null;
			return;
		}
	 	this.srAddTime=Utils.date(strValue,"yyyy-MM-dd HH:mm:ss");
	}
	
	/**
	* 添加时间 [非空]      
	**/
	public void setSrAddTime(Date srAddTime){
		this.srAddTime = srAddTime;
		this.setSeted(F.srAddTime);
	}
	
	
	
	
	/*******************************状态**********************************/	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public Short getSrStatus(){
		if(this.srStatus!=null){
			return this.srStatus;
		}
		return this.srStatus;
	}
	/**
	* 获取状态格式化(toString)
	**/
	public String getSrStatus$(){
		String strValue="";
		 if(Utils.equals(Utils.string(this.getSrStatus()),"1"))
			strValue=Utils.string("正常");		 
		 if(Utils.equals(Utils.string(this.getSrStatus()),"0"))
			strValue=Utils.string("无效");		 
	 	 return strValue;
	}
	/**
	* 根据状态反格式化
	**/
	public void setSrStatus$(String strValue){
		if(Utils.empty(strValue)){
			this.srStatus=null;
			return;
		}
		 if(Utils.equals(strValue,"正常"))
		 	this.srStatus=Utils.parseShort("1");
		 if(Utils.equals(strValue,"无效"))
		 	this.srStatus=Utils.parseShort("0");
	}
	
	/**
	* 状态 [非空]   1:正常 0:无效    
	**/
	public void setSrStatus(Short srStatus){
		this.srStatus = srStatus;
		this.setSeted(F.srStatus);
	}
	
	
	
	
	/************LAZY3Q_DEFINE_CODE************/
	/************LAZY3Q_DEFINE_CODE************/
	
	
	/**
	 * 触发器
	 */
	public static void on(Trigger.Index index,final Notify.Listener listener,Trigger.Type... types){
		Notify.on(SrvRole.class, index, listener, types);
	}
	public static void on(final Notify.Listener listener,String type){
		Notify.on(SrvRole.class, listener, type);
	}
	/**
	 * 当修改字段时
	 * @param filedName
	 * @param listener
	 */
	public static void on(String filedName,final Notify.Listener listener){
		Notify.on(SrvRole.class, listener, filedName);
	}
	/**
	 * 当修改字段为某值时
	 * @param filedName
	 * @param value
	 * @param listener
	 */
	public static void on(String filedName,Object value,final Notify.Listener listener){
		if(value==null)return;
		Notify.on(SrvRole.class, listener, filedName+"."+Utils.md5(""+value));
	}
	public void notify(String type){
		Trigger.on(SrvRole.class,type, this);
	}
	
	
	/**
	 * 用来获取当有字段关联对象时的获取方式,调用如${SrvRole.obj.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvRole.$filedName}获取关联对象
	 */
	public Map getObj(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvRole.class.getMethod("get$"+Utils.forMat(key.toString())).invoke(SrvRole.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 用来获取某字段格式化的获取方式,调用如${SrvRole.fmt.filedName}
	 * 因为有些变态的模板语言不能识别$，所以不能以${SrvRole.filedName$}获取某字段格式化
	 */
	public Map getFmt(){
		return new HashMap(){
			@Override
			public Object get(Object key) {
				try {
					return SrvRole.class.getMethod("get"+Utils.ForMat(key.toString()+"$")).invoke(SrvRole.this);
				} catch (Exception e) {
					e.printStackTrace();
				}
				return null;
			}
		};
	}
	/**
	 * 获取查询参数链式串
	 * @return
	 */
	public static @Deprecated M where(){ return new M(0); }
	public static @Deprecated M m(){ return new M(0); }
	public static M where = new M(0,true);
	public static @database(DatabaseNames.distribute_sys) class M extends IbatisMap{
		int type = 0; 
		M linked = null;
		Boolean proxy = false;
		public M set = null;
		public M(int type){
			this.type = type;
			if(this.type==0){
				set = new M(1,true);
				set.linked = this;
			}
		};
		public M(int type,Boolean proxy){
			this.type = type;
			this.proxy=proxy;
		};
		public M proxy(){
			M m = new M(this.type);//当前的对像
			if(this.type==0){
				m.set = new M(1,true);//set对象
				m.set.linked = m;
			}else{
				m.linked=this.linked;
				this.linked.linked=m;
			}
			return m;
		}
		public @Deprecated M set(){			
			M m = this;
			m.linked=new M(1);
			m.linked.linked=m;
			return m.linked;
		};
		public M on(IbatisMap value,C column,String joinColumn){if(proxy)return proxy().on(value,column,joinColumn);this.put(value.getClass().getDeclaringClass().getSimpleName(), value);value.put("on", column.toString());value.put("to", joinColumn);return this;};
		/** 编号 [非空]       **/
		public M srId(Object srId){if(proxy)return proxy().srId(srId);  this.put("srId", srId);return this;};
	 	/** and sr_id is null */
 		public M srIdNull(){if(proxy)return proxy().srIdNull();if(this.get("srIdNot")==null)this.put("srIdNot", "");this.put("srId", null);return this;};
 		/** not .... */
 		public M srIdNot(){if(proxy)return proxy().srIdNot();this.put("srIdNot", "not");return this;};
 		public M srIdNotNull(){if(proxy)return proxy().srIdNotNull();this.put("srIdNot", "not");this.put("srId", null);return this;};
 		public M srIdNot(Object srId){if(proxy)return proxy().srIdNot(srId);this.put("srIdNot", "not");this.put("srId", srId);return this;};
		/** and sr_id <= ? */
		public M srIdMin(Object min){if(proxy)return proxy().srIdMin(min);this.put("srIdMin", min);return this;};
		/** and sr_id >= ? */
		public M srIdMax(Object max){if(proxy)return proxy().srIdMax(max);this.put("srIdMax", max);return this;};
		public M srIdIn(String ids){
			if(proxy)return proxy().srIdIn(ids);  this.put("srIdIn", ids);return this;
		};	
		/** 角色名称 [非空]       **/
		public M srName(Object srName){if(proxy)return proxy().srName(srName);  this.put("srName", srName);return this;};
	 	/** and sr_name is null */
 		public M srNameNull(){if(proxy)return proxy().srNameNull();if(this.get("srNameNot")==null)this.put("srNameNot", "");this.put("srName", null);return this;};
 		/** not .... */
 		public M srNameNot(){if(proxy)return proxy().srNameNot();this.put("srNameNot", "not");return this;};
 		public M srNameNotNull(){if(proxy)return proxy().srNameNotNull();this.put("srNameNot", "not");this.put("srName", null);return this;};
 		public M srNameNot(Object srName){if(proxy)return proxy().srNameNot(srName);this.put("srNameNot", "not");this.put("srName", srName);return this;};
		/** 角色标识        **/
		public M srFlag(Object srFlag){if(proxy)return proxy().srFlag(srFlag);  this.put("srFlag", srFlag);return this;};
	 	/** and sr_flag is null */
 		public M srFlagNull(){if(proxy)return proxy().srFlagNull();if(this.get("srFlagNot")==null)this.put("srFlagNot", "");this.put("srFlag", null);return this;};
 		/** not .... */
 		public M srFlagNot(){if(proxy)return proxy().srFlagNot();this.put("srFlagNot", "not");return this;};
 		public M srFlagNotNull(){if(proxy)return proxy().srFlagNotNull();this.put("srFlagNot", "not");this.put("srFlag", null);return this;};
 		public M srFlagNot(Object srFlag){if(proxy)return proxy().srFlagNot(srFlag);this.put("srFlagNot", "not");this.put("srFlag", srFlag);return this;};
		/** 角色描述        **/
		public M srProfile(Object srProfile){if(proxy)return proxy().srProfile(srProfile);  this.put("srProfile", srProfile);return this;};
	 	/** and sr_profile is null */
 		public M srProfileNull(){if(proxy)return proxy().srProfileNull();if(this.get("srProfileNot")==null)this.put("srProfileNot", "");this.put("srProfile", null);return this;};
 		/** not .... */
 		public M srProfileNot(){if(proxy)return proxy().srProfileNot();this.put("srProfileNot", "not");return this;};
 		public M srProfileNotNull(){if(proxy)return proxy().srProfileNotNull();this.put("srProfileNot", "not");this.put("srProfile", null);return this;};
 		public M srProfileNot(Object srProfile){if(proxy)return proxy().srProfileNot(srProfile);this.put("srProfileNot", "not");this.put("srProfile", srProfile);return this;};
		/** 修改时间 [非空]       **/
		public M srUpdateTime(Object srUpdateTime){if(proxy)return proxy().srUpdateTime(srUpdateTime);  this.put("srUpdateTime", srUpdateTime);return this;};
	 	/** and sr_update_time is null */
 		public M srUpdateTimeNull(){if(proxy)return proxy().srUpdateTimeNull();if(this.get("srUpdateTimeNot")==null)this.put("srUpdateTimeNot", "");this.put("srUpdateTime", null);return this;};
 		/** not .... */
 		public M srUpdateTimeNot(){if(proxy)return proxy().srUpdateTimeNot();this.put("srUpdateTimeNot", "not");return this;};
 		public M srUpdateTimeNotNull(){if(proxy)return proxy().srUpdateTimeNotNull();this.put("srUpdateTimeNot", "not");this.put("srUpdateTime", null);return this;};
 		public M srUpdateTimeNot(Object srUpdateTime){if(proxy)return proxy().srUpdateTimeNot(srUpdateTime);this.put("srUpdateTimeNot", "not");this.put("srUpdateTime", srUpdateTime);return this;};
 		/** and sr_update_time >= ? */
 		public M srUpdateTimeStart(Object start){if(proxy)return proxy().srUpdateTimeStart(start);this.put("srUpdateTimeStart", start);return this;};			
 		/** and sr_update_time <= ? */
 		public M srUpdateTimeEnd(Object end){if(proxy)return proxy().srUpdateTimeEnd(end);this.put("srUpdateTimeEnd", end);return this;};
		/** 添加时间 [非空]       **/
		public M srAddTime(Object srAddTime){if(proxy)return proxy().srAddTime(srAddTime);  this.put("srAddTime", srAddTime);return this;};
	 	/** and sr_add_time is null */
 		public M srAddTimeNull(){if(proxy)return proxy().srAddTimeNull();if(this.get("srAddTimeNot")==null)this.put("srAddTimeNot", "");this.put("srAddTime", null);return this;};
 		/** not .... */
 		public M srAddTimeNot(){if(proxy)return proxy().srAddTimeNot();this.put("srAddTimeNot", "not");return this;};
 		public M srAddTimeNotNull(){if(proxy)return proxy().srAddTimeNotNull();this.put("srAddTimeNot", "not");this.put("srAddTime", null);return this;};
 		public M srAddTimeNot(Object srAddTime){if(proxy)return proxy().srAddTimeNot(srAddTime);this.put("srAddTimeNot", "not");this.put("srAddTime", srAddTime);return this;};
 		/** and sr_add_time >= ? */
 		public M srAddTimeStart(Object start){if(proxy)return proxy().srAddTimeStart(start);this.put("srAddTimeStart", start);return this;};			
 		/** and sr_add_time <= ? */
 		public M srAddTimeEnd(Object end){if(proxy)return proxy().srAddTimeEnd(end);this.put("srAddTimeEnd", end);return this;};
		/** 状态 [非空]   1:正常 0:无效     **/
		public M srStatus(Object srStatus){if(proxy)return proxy().srStatus(srStatus);  this.put("srStatus", srStatus);return this;};
	 	/** and sr_status is null */
 		public M srStatusNull(){if(proxy)return proxy().srStatusNull();if(this.get("srStatusNot")==null)this.put("srStatusNot", "");this.put("srStatus", null);return this;};
 		/** not .... */
 		public M srStatusNot(){if(proxy)return proxy().srStatusNot();this.put("srStatusNot", "not");return this;};
 		public M srStatusNotNull(){if(proxy)return proxy().srStatusNotNull();this.put("srStatusNot", "not");this.put("srStatus", null);return this;};
 		public M srStatusNot(Object srStatus){if(proxy)return proxy().srStatusNot(srStatus);this.put("srStatusNot", "not");this.put("srStatus", srStatus);return this;};
		public M srStatusIn(String ids){
			if(proxy)return proxy().srStatusIn(ids);  this.put("srStatusIn", ids);return this;
		};	
	 	public M add(String key, Object value) {if(proxy)return proxy().add(key,value);this.put(key, value);return this;}
	 	public M add(F key, Object value) {if(proxy)return proxy().add(key,value);this.put(key.toString(), value);return this;}
	 	public M desc(C key) {if(proxy)return proxy().desc(key);this.put("desc", key.column);return this;}
	 	public M asc(C key) {if(proxy)return proxy().asc(key);this.put("asc", key.column);return this;}
	 	public M desc(String sql) {if(proxy)return proxy().desc(sql);this.put("desc", sql);return this;}
	 	public M asc(String sql) {if(proxy)return proxy().asc(sql);this.put("asc", sql);return this;}
	 	public M definex(String sql) {if(proxy)return proxy().definex(sql);this.put("definex", sql);return this;}
	 	/** 获取所有系统角色 **/
		public @api List<SrvRole> list(Integer size){			
			return getSrvRoleList(this,size);
		}
		/** 获取系统角色分页 **/
		public @api Page<SrvRole> page(Integer page,Integer size){			
			return getSrvRolePage(page, size , this);
		}
		/** 根据查询条件取系统角色 **/
		public @api SrvRole get(){			
			return getSrvRole(this);
		}
		/** 获取系统角色数 **/
		public @api Long count(){			
			return getSrvRoleCount(this);
		}
		/** 获取系统角色表达式 **/
		public @api <T> T eval(String strEval){			
			return getSrvRoleEval(strEval,this);
		}
		/** 获取系统角色统计 **/
		public @api List<Map> stats(C sumKey,C groupKey,int dateType){			
			return getSrvRoleStats(this,sumKey,groupKey,dateType);
		}
		/** 获取系统角色统计 **/
		public @api List<Map> stats(C sumKey,C groupKey){			
			return getSrvRoleStats(this,sumKey,groupKey,-1);
		}
		/** 根据条件更新 **/
		public @api int update(){			
			M where = null;
			M set = null;
			if(this.type==0){
				if(this.linked==null)throw new RuntimeException("未发set");
				where = this;
				set = this.linked;
			}else{
				if(this.linked==null)throw new RuntimeException("未发where条件");
				set = this;
				where = this.linked;
			}
			return updateSrvRole(set,where);
		}
		/** 根据条件删除 **/
		public @api void delete(){			
			deleteSrvRole(this);
		}
	}
	
	public static class Param extends M{
		public Param(int type) {
			super(type);
		}
		public Param(int type, Boolean proxy) {
			super(type, proxy);
		}
	}
	
	/** 对象的字段描述 **/
	public static class F{
		/** 编号 [非空]       **/
		public final static @type(Long.class)  String srId="srId";
		/** 角色名称 [非空]       **/
		public final static @type(String.class)  String srName="srName";
		/** 角色标识        **/
		public final static @type(String.class)  String srFlag="srFlag";
		/** 角色描述        **/
		public final static @type(String.class) @like String srProfile="srProfile";
		/** 修改时间 [非空]       **/
		public final static @type(Date.class)  String srUpdateTime="srUpdateTime";
	 	/** and sr_update_time >= ? */
 		public final static @type(Date.class) String srUpdateTimeStart="srUpdateTimeStart";
 		/** and sr_update_time <= ? */
 		public final static @type(Date.class) String srUpdateTimeEnd="srUpdateTimeEnd";
		/** 添加时间 [非空]       **/
		public final static @type(Date.class)  String srAddTime="srAddTime";
	 	/** and sr_add_time >= ? */
 		public final static @type(Date.class) String srAddTimeStart="srAddTimeStart";
 		/** and sr_add_time <= ? */
 		public final static @type(Date.class) String srAddTimeEnd="srAddTimeEnd";
		/** 状态 [非空]   1:正常 0:无效     **/
		public final static @type(Short.class)  String srStatus="srStatus";
	 	public static String get(String name){
			try {
				Field field = F.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	/** 对象的数据库字段描述 **/
	public static enum C{
		srId("sr_id"),
		srName("sr_name"),
		srFlag("sr_flag"),
		srProfile("sr_profile"),
		srUpdateTime("sr_update_time"),
		srAddTime("sr_add_time"),
		srStatus("sr_status"),
		count("count");
		String column;
		C(String column){
			this.column = column;
		}
		public String toString(){
			return this.column;
		}
		public static String get(String name){
			try {
				Field field = C.class.getField(name);
				if(field!=null)
					return field.get(null).toString();
			} catch (Exception e) {
				//e.printStackTrace();
			}
			return null;
		}
	}
	
	
	
	/**
	* 获取系统角色数据
	**/
	public static Object getData(Object param){
		if(param==null)
			return null;
		Object value = null;
		if(param.getClass()==Long.class)
			value = SrvRole.get((Long)param);
		else if(param instanceof java.util.Map){
			java.util.Map params = (Map) param;
			if(params.get("size")==null)
				value = SrvRole.getSrvRole(params);
			else
				value = SrvRole.getSrvRoleList(params, (Integer) params.get("size"));
		}else if(param.getClass()==Long.class )
			value =  SrvRole.where().srId(param).get();
		else if(!Utils.empty(param.toString()))
			value = SrvRole.get(Long.valueOf(param.toString()));
		return value;
	}
	
	/**对象转json**/
	public Map toJSON(){
		return toJSON(false);
	}
	public Map toJSON(boolean simple){
		Map map = new HashMap();
		map.put("id",this.getSrId());
		Utils.fms(map,simple?"id":"srId",this.getSrId(),this.getSrId$());
		Utils.fms(map,simple?"name":"srName",this.getSrName(),this.getSrName$());
		Utils.fms(map,simple?"flag":"srFlag",this.getSrFlag(),this.getSrFlag$());
		Utils.fms(map,simple?"profile":"srProfile",this.getSrProfile(),this.getSrProfile$());
		Utils.fms(map,simple?"updateTime":"srUpdateTime",this.getSrUpdateTime(),this.getSrUpdateTime$());
		Utils.fms(map,simple?"addTime":"srAddTime",this.getSrAddTime(),this.getSrAddTime$());
		Utils.fms(map,simple?"status":"srStatus",this.getSrStatus(),this.getSrStatus$());
		if(this.suffix!=null)map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOJSON************/
		/************LAZY3Q_DEFINE_TOJSON************/
		return map;
	}
	/**对象转map**/
	public Map toMap(){
		Map map = new HashMap();
		map.put("srId",this.getSrId());
		map.put("srName",this.getSrName());
		map.put("srFlag",this.getSrFlag());
		map.put("srProfile",this.getSrProfile());
		map.put("srUpdateTime",this.getSrUpdateTime());
		map.put("srAddTime",this.getSrAddTime());
		map.put("srStatus",this.getSrStatus());
		map.put("suffix", this.suffix);
		/************LAZY3Q_DEFINE_TOMAP************/
		/************LAZY3Q_DEFINE_TOMAP************/
		return map;
	}
	/**map转对象**/
	public static SrvRole fromMap(Map map){
		SrvRole srvRole = new SrvRole();
		srvRole.srId = Utils.parseLong(map.get("srId"));
		srvRole.srName = Utils.parseString(map.get("srName"));
		srvRole.srFlag = Utils.parseString(map.get("srFlag"));
		srvRole.srProfile = Utils.parseString(map.get("srProfile"));
		srvRole.srUpdateTime = Utils.parseDate(map.get("srUpdateTime"));
		srvRole.srAddTime = Utils.parseDate(map.get("srAddTime"));
		srvRole.srStatus = Utils.parseShort(map.get("srStatus"));
		return srvRole;
	}
	
	
	
	/**字段设置标记队列**/
	private Map<String,Boolean> seted=new HashMap();
	public Boolean getSeted(String key){
		return seted.get(key);
	}
	public void setSeted(String key){
		seted.put(key,true);
	}
	/**同步未set的字段**/
	public void mergeSet(SrvRole old){
		Field[] fields = this.getClass().getDeclaredFields();
		try {
			for(Field field:fields){
				String key = field.getName();
				if(seted.get(key)==null && field.getAnnotation(column.class)!=null){
					field.setAccessible(true);
					field.set(this, field.get(old));					
				}
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}
	
		
	/**自定义变量存储**/
	private Map values=new HashMap();
	public Map getValues(){
		return values;
	}
	public void setValues(String name,Object value){
		values.put(name,value);
	}
	
	/**分表时的表名后缀**/
	private String suffix;
	public String getSuffix() {
		return suffix;
	}
	public void setSuffix(String suffix) {
		this.suffix = suffix;
	}
	/**获取数据库名称**/
	public static String getDataBaseName(){
		return Utils.config("spring.datasource.distribute_sys.name");
	}
	
	public static String getIcon(){
		return "/images/icons/2008112220121595877802.png";
	}
	public static String getIconfont(){
		return "icon-nan";
	}
	public static enum ACT{
		列表,添加,修改,详情
	};
	public static String getUrl(ACT act,SrvRole.M params){
		if(params==null)params=new SrvRole.M(0);
		params.remove("joins");
		params.remove("definexs");
		params.remove("distinct");
		String strUrl = "/admin/permissions/role.edit.html?";
		if(params.get("srId")!=null){
			strUrl+="&id="+Utils.encode(""+params.get("srId"),Utils.UTF8);
		}
		if(act==ACT.列表){
			strUrl = "/admin/permissions/role.html?1=1";
		}else if(act==ACT.添加){
			strUrl+="&edittype=insert";
		}else if(act==ACT.修改){
			strUrl+="&edittype=update";
		}else if(act==ACT.详情){
			strUrl+="&edittype=detail";
		}		
		if(params!=null){
			for(Object key:params.keySet()){
				strUrl+="&"+key+"="+Utils.encode(""+params.get(key),Utils.UTF8)+"";
			}
		}
		return strUrl;
	}
	public String getDetailUrl(){
		return this.getUrl(ACT.详情, where.srId(this.getId()));
	}
	
	/**
	* 转跳到当前地址
	**/
	public static Protocol redirect(SrvRole.ACT act,SrvRole.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_REDIRECT");
		protocol.set("url",SrvRole.getUrl(act, params));
		return protocol;
	}
	/**
	* 打开一个新的tab页面
	**/
	public static Protocol href(SrvRole.ACT act,SrvRole.M params){
		Protocol protocol = Protocol.create(true,null,"ACT_HREF");
		protocol.set("url",SrvRole.getUrl(act, params));
		protocol.set("title",act.name());
		return protocol;
	}
	/**
	* 显示一个消息框，并且关闭当前的对话框
	**/
	public static Protocol message(String message){
		Protocol protocol = Protocol.create(true,null,"ACT_MESSAGE");
		protocol.set("message",message);
		return protocol;
	}
	
	
	static com.distribute.framework.dao.ISrvRoleDao getSrvRoleDao(){
		return Utils.getBean("srvRoleDao");
	};
	
}